home *** CD-ROM | disk | FTP | other *** search
- /* cmdline.cpp
-
- Command line version of maplay written by John Fehr
-
- This can be used for unix systems as well as the Win32 console. */
-
- #ifdef __WIN32__
- #define STRICT
- #include <windows.h>
- #endif // __WIN32__
-
- #include <stdio.h>
- #include <string.h>
- #include <iostream.h>
-
- #include "all.h"
- #include "crc.h"
- #include "args.h"
-
- // What character marks the end of a directory entry? For DOS and
- // Windows, it is "\"; in UNIX it is "/".
- #ifdef __WIN32__
- #define DIR_MARKER '\\'
- #else
- #define DIR_MARKER '/'
- #endif
-
- #ifdef __WIN32__
- HWAVEOUT hwo;
- #endif
-
- BOOL verbose_mode = FALSE;
- char filename[512] = "";
-
- uint32 maplay(MPEG_Args *);
-
- int ProcessArgs(int argc,char *argv[],MPEG_Args *);
-
- int Usage(char *pname)
- {
- cerr << "\nusage: " << pname
- << " [-v] [-s] [-l] [-r] "
- #ifdef SPARC
- "[-us] [-uh] "
- #ifndef SunOS4_1_1
- "[-ul] "
- #endif
- #endif
- "[-f ushort] filename\n"
- " filename filename of a MPEG audio stream or - for stdin\n"
- #ifdef VERBOSE
- " -v verbose mode\n"
- #endif
- #ifdef ULAW
- " -s write u-law samples at 8 kHz rate to stdout\n"
- #else
- " -s write pcm samples to stdout\n"
- #endif
- " -l decode only the left channel\n"
- " -r decode only the right channel\n"
- " -d downmix mode (layer III only)\n"
- #ifdef SPARC
- " -us send audio signal to speaker (default)\n"
- " -uh send audio signal to headphone\n"
- #ifndef SunOS4_1_1
- " -ul send audio signal to line out\n"
- #endif
- #endif
- #ifdef ULAW
- " -amd force maplay to treat /dev/audio as an amd device\n"
- #endif
- #ifdef VERBOSE
- " -c check for filter range violations\n"
- #endif
- " -f ushort use this scalefactor instead of the default value 32768\n\n"
- "@(#) MPEG Audio Player maplay 1.2+ "
- #ifdef ULAW
- "(8 kHz u-law "
- #else
- "("
- #endif
- #ifdef Indigo
- "SGI IRIX"
- #else
- #ifdef SunOS4_1_1
- "SPARC SunOS 4.1.1"
- #else
- #ifdef SunOS4_1_3
- "SPARC SunOS 4.1.3"
- #else
- #ifdef Solaris
- "SPARC Solaris 2.x"
- #else
- #ifdef LINUX
- "Linux"
- #else
- #ifdef ULTRIX
- "RISC ULTRIX 4.x"
- #else
- #ifdef HPUX
- "HPUX 10.10"
- #else
- #ifdef AIX
- "AIX"
- #else
- #ifdef NeXT
- "NeXTStep 3.2"
- #else
- #ifdef __WIN32__
- "Win32 Console"
- #else
- "unknown"
- #endif // _WIN32__
- #endif // NeXT
- #endif // AIX
- #endif // HPUX
- #endif // ULTRIX
- #endif // LINUX
- #endif // Solaris
- #endif // SunOS4_1_3
- #endif // SunOS4_1_1
- #endif // Indigo
-
- " version)\n"
- "@(#) Copyright (C) 1996, 1997 Jeff Tsay (ctsay@pasteur.eecs.berkeley.edu)\n"
- "@(#) This re-ported commandline version 1.81 by John Fehr (jfehr@themall.net)\n"
- "@(#)\n"
- "@(#) Original maplay 1.2:\n"
- "@(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)\n"
- "@(#) Berlin University of Technology\n"
- "@(#)\n"
- "@(#) Layer III code adapted from the ISO MPEG Audio Subgroup Software\n"
- "@(#) Simulation Group\n"
- "@(#)\n"
- "@(#) Created: 04/19/97 (Pentium version)\n"
- "@(#) This program is free software. See the GNU General Public License\n"
- "@(#) in the file COPYING for more details.\n\n"
- ;
- return 0;
- }
-
- int ProcessArgs(int32 argc,char *argv[],MPEG_Args *ma)
- {
-
- Crc16 *crc = NULL;
- int i;
-
- ma->stdout_mode = FALSE;
-
- #ifdef __WIN32__
- ma->phwo = &hwo;
- #endif
-
- if (argc < 2 || !strncmp (argv[1], "-h", 2))
- {
- return Usage(argv[0]);
- }
- // parse arguments:
- for (i = 1; i < argc; ++i)
- if (argv[i][0] == '-' && argv[i][1])
- switch ((int32)argv[i][1])
- {
- case 'v':
- #ifdef VERBOSE
- verbose_mode = TRUE;
- #else
- cerr << "maplay: not compiled with VERBOSE." << endl;
- #endif
- break;
- case 's':
- ma->stdout_mode = TRUE;
- break;
- case 'l':
- ma->which_c = left;
- break;
- case 'r':
- ma->which_c = right;
- break;
- case 'd':
- ma->which_c = downmix;
- break;
-
- #ifdef SPARC
- case 'u':
- switch (argv[i][2])
- {
- case 's':
- ma->use_speaker = TRUE;
- break;
- case 'h':
- ma->use_headphone = TRUE;
- break;
- #ifndef SunOS4_1_1
- case 'l':
- ma->use_line_out = TRUE;
- break;
- #endif
- default:
- return Usage(argv[0]);
- }
- break;
- #endif
- #ifdef ULAW
- case 'a':
- ma->force_amd = TRUE;
- break;
- #endif
- case 'c':
- cerr << "Sorry, this version does not support filter checking.\n" << endl;
- break;
- case 'f':
- if (++i == argc)
- {
- cerr << "please specify a new scalefactor after the -f option!\n";
- exit (1);
- }
- ma->use_own_scalefactor = TRUE;
- sscanf (argv[i], "%f", &ma->scalefactor);
- break;
- default:
- return Usage(argv[0]);
- }
- else if (!filename[0])
- strcpy(filename,argv[i]);
- else
- return Usage(argv[0]);
-
- if (!filename[0])
- return Usage(argv[0]);
-
- #if defined(SPARC) || defined(HPUX)
- if (!(ma->use_speaker || ma->use_headphone || ma->use_line_out))
- ma->use_speaker = TRUE;
- #endif // SPARC || HPUX
-
- if (!strcmp (filename, "-"))
- ma->stream = new Ibitstream (0); // read from stdin
- else
- ma->stream = new Ibitstream (filename); // read from file
-
- ma->MPEGheader = new Header;
- if (!ma->MPEGheader->read_header (ma->stream, &crc))
- {
- cerr << endl << "Error : no header found!" << endl;
- return(0);
- }
- return(1);
- }
-
- int maplay_setup (MPEG_Args *ma)
- {
-
- #ifdef VERBOSE
- if (verbose_mode)
- {
- // print information about the stream
- char *name = strrchr (filename, DIR_MARKER);
- if (name)
- ++name;
- else
- name = filename;
- cerr << name << " is a layer " << ma->MPEGheader->layer_string () << ' '
- << ma->MPEGheader->mode_string () << " MPEG audio stream with";
- if (!ma->MPEGheader->checksums ())
- cerr << "out";
- cerr << " checksums.\nThe sample frequency is "
- << ma->MPEGheader->sample_frequency_string () << " at a bitrate of "
- << ma->MPEGheader->bitrate_string () << ".\n"
- "This stream is ";
- if (ma->MPEGheader->original ())
- cerr << "an original";
- else
- cerr << "a copy";
- cerr << " and is ";
- if (!ma->MPEGheader->copyright ())
- cerr << "not ";
- cerr << "copyright protected.\n";
- }
- #endif
- return(1);
- }
-
- int main(int argc,char *argv[])
- {
- MPEG_Args ma;
- if (!ProcessArgs(argc,argv,&ma)) return(0);
- maplay_setup(&ma);
- maplay(&ma);
- return(0);
- }
-